﻿myApp.controller("AgentsController", function ($scope, $http, $modal, modalService, $routeParams,ngTableParams,$filter, $location) {
    document.title = "Penang Realty 世界地產 Agents";
    $scope.$emit('newPageLoaded', { 'title': 'Penang Realty 世界地產 Agents', 'description': 'Professional property agents.' });
    function pageInit() {
            $scope.loader = { loading: true };
            var url = 'api/User/GetAgentList';
            $http.get(url).success(function (data) {
                $scope.data.Info = data;
                console.log(data);
                $scope.tableParams = new ngTableParams({
                    page: 1,            // show first page
                    count: 25,           // count per page
                    filter: {
                        username: ''       // initial filter
                    }

                }, {
                    total: $scope.data.Info.length, // length of data
                    getData: function ($defer, params) {

                        var orderedInfo= params.filter() ? $filter('filter')($scope.data.Info, params.filter()) : $scope.data.Info;
                        // use build-in angular filter
                        orderedInfo = params.sorting() ? $filter('orderBy')(orderedInfo, params.orderBy()) : orderedInfo;
                        params.total(orderedInfo.length); // set total for recalc pagination
                        $defer.resolve(orderedInfo.slice((params.page() - 1) * params.count(), params.page() * params.count()));
                        $scope.loader = { loading: false };
                    }
                })


            })

    }

    function pageInit2() {
        var load = false;
        //window.onload = function () {
        console.log("water mark script onload in agentController");
        if (!load) {
            wmark.init({
                /* config goes here */
                "position": "top-right", // default "bottom-right"
                "opacity": 50, // default 50
                "className": "watermark", // default "watermark"
                "path": "../images/qr.png"
            });
            load = true;
        }
        //}
    }

    //pageInit2();
    pageInit();


})

